package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptors.MyInterceptor1;
import cn.tedu._06interceptor.interceptors.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * WebMvcConfigurer:
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1.拦截策略1:默认拦截所有请求
        /*registry.addInterceptor(new MyInterceptor1());*/

        //2.拦截策略2:拦截指定的请求[1个或多个].只拦截登录和注册两个请求
//        registry.addInterceptor(new MyInterceptor1()).addPathPatterns("/v1/users/login","/v1/users/reg");

        //3.拦截策略3:拦截指定模块的请求:拦截用户模块的所有请求
        /*registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/users/**");*/

        //4.拦截策略4:排除指定的请求,用户模块中拦截除了登录之外的所有请求
        /*registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/users/**")
                .excludePathPatterns("/v1/users/login");*/
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
    }
}
